use processed/RPImicro,clear

forvalues x = 1/17	 {
gen b`x' = s_RPI_`x'
drop if b`x' ==.
}

gen logI = log(I)
keep if I > 0
qui forvalues x = 1/17	 {
keep if b`x' <1 
keep if b`x' > -0.00001 
}




qui forvalues s = 1/500  {
preserve
bsample , strata(datayear)	

* Lowess

qui forvalues x = 1/17	 {
	lowess b`x' logI  if datayear ==1974, generate(tmp) nograph
	gen b`x'_hat = tmp
	drop tmp
}

qui forvalues t = 1975/2017 {

qui forvalues x = 1/17 {
	lowess b`x' logI  if datayear == `t', generate(tmp) nograph
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
} 
}

keep datayear I b1_hat b2_hat b3_hat b4_hat b5_hat b6_hat b7_hat b8_hat b9_hat b10_hat b11_hat b12_hat b13_hat b14_hat b15_hat b16_hat b17_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using bootstrap_samples/csv/UK_Budget_boot_`s'.csv, comma replace nonames
restore
}


// baseline

qui forvalues x = 1/17	 {
	lowess b`x' logI  if datayear ==2001, generate(tmp) nograph
	gen b`x'_hat = tmp
	drop tmp
}

qui forvalues t = 2002/2017 {

qui forvalues x = 1/17 {
	lowess b`x' logI  if datayear == `t', generate(tmp) nograph
	replace b`x'_hat = tmp if datayear == `t'
	drop tmp
} 
}

keep datayear I b1_hat b2_hat b3_hat b4_hat b5_hat b6_hat b7_hat b8_hat b9_hat b10_hat b11_hat b12_hat b13_hat b14_hat b15_hat b16_hat b17_hat weight caseno
duplicates drop caseno datayear,force
drop caseno

outsheet using bootstrap_samples/csv/UK_Budget_boot_0.csv, comma replace nonames

